package com.shortlink.admin.controller;

import com.shortlink.admin.dto.req.group.GroupInsertReqDTO;
import com.shortlink.admin.dto.req.group.GroupSortReqDTO;
import com.shortlink.admin.dto.req.group.GroupUpdateReqDTO;
import com.shortlink.admin.dto.resp.group.GroupRespDTO;
import com.shortlink.admin.service.GroupService;
import com.shortlink.common.base.Result;
import com.shortlink.common.base.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 短链接分组控制层
 *
 * @author wp
 */
@RestController
@RequiredArgsConstructor
public class GroupController {
    private final GroupService groupService;

    /**
     * 用户新增短链接分组
     */
    @PostMapping("/web-api/groups/save")
    public Result<Void> save(@RequestBody GroupInsertReqDTO groupInsert) {
        groupService.saveGroup(groupInsert);
        return Results.success();
    }

    /**
     * 用户查询短链接分组集合
     */
    @GetMapping("/web-api/groups/list")
    public Result<List<GroupRespDTO>> listGroup() {
        return Results.success(groupService.listGroup());
    }

    /**
     * 用户修改短链接分组名称
     */
    @PutMapping("/web-api/groups/update")
    public Result<Void> updateGroup(@RequestBody GroupUpdateReqDTO groupUpdate) {
        groupService.updateGroup(groupUpdate);
        return Results.success();
    }

    /**
     * 用户删除短链接分组
     */
    @DeleteMapping("/web-api/groups/delete/{gid}")
    public Result<Void> updateGroup(@PathVariable("gid") Long gid) {
        groupService.deleteGroup(gid);
        return Results.success();
    }

    /**
     * 用户排序短链接分组
     */
    @PostMapping("/web-api/groups/sort")
    public Result<Void> sortGroup(@RequestBody GroupSortReqDTO groupSortReq) {
        groupService.sortGroup(groupSortReq);
        return Results.success();
    }
}
